﻿using GameFramework;
using UnityEngine;
using UnityGameFramework.Runtime;
using LuaFramework;
using UnityEngine.UI;

public class MainPanel : UIFormLogic
{
    public Text nameText;
    public Text lvText;
    public Text fightText;

    ProcedureMainScene procedureMainScene;
    protected internal override void OnOpen(object userData)
    {
        base.OnOpen(userData);
        procedureMainScene = (ProcedureMainScene)userData;

        EventDispatcher.AddEventListener<HeroData>(EventKey.SCOnHeroInfo, OnReceiveHeroInfo);

        //玩家信息改变事件监听
        //EventDispatcher.AddEventListener<string>(EventKey.SCOnRequestPlayerName,OnReceivePlayerName);

        //打开界面向服务器请求玩家数据(所有)
        EventDispatcher.TriggerEvent(EventKey.CSOnHeroInfo);

        
    }

    /// <summary>
    /// 冒险
    /// </summary>
    public void AdventureBtnClick()
    {
        //根据表里面的场景名称
        procedureMainScene.EnterGame("001");
    }

    //接收到服务器返回的玩家信息
    public void OnReceiveHeroInfo(HeroData data)
    {
        //Debug.Log(data);
        nameText.text = data.name;
        lvText.text = data.lv.ToString();
        fightText.text = data.fightValue.ToString();

    }

    protected internal override void OnClose(object userData)
    {
        base.OnClose(userData);
        EventDispatcher.RemoveEventListener<HeroData>(EventKey.SCOnHeroInfo, OnReceiveHeroInfo);
    }
}
